<?php
/*
 *                        _oo0oo_
 *                       o8888888o
 *                       88" . "88
 *                       (| -_- |)
 *                       0\  =  /0
 *                     ___/`---'\___
 *                   .' \\|     |// '.
 *                  / \\|||  :  |||// \
 *                 / _||||| -:- |||||- \
 *                |   | \\\  - /// |   |
 *                | \_|  ''\---/''  |_/ |
 *                \  .-\__  '-'  ___/-. /
 *              ___'. .'  /--.--\  `. .'___
 *           ."" '<  `.___\_<|>_/___.' >' "".
 *          | | :  `- \`.;`\ _ /`;.`/ - ` : | |
 *          \  \ `_.   \_ __\ /__ _/   .-` /  /
 *      =====`-.____`.___ \_____/___.-`___.-'=====
 *                        `=---='
 * 
 * 
 *      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * 
 *            佛祖保佑       永不宕机     永无BUG
 */
/*
 * 搜索页
 * @Author: htong
 * @Date: 2021-03-02 18:16:55
 * @LastEditors: htong
 * @LastEditTime: 2021-03-02 18:39:06
 * @Description: file content
 * @FilePath: \gongchengqiaojob\Application\Home\Controller\PcresumeApiController.class.php
 */
namespace Home\Controller;
use Common\Controller\PcApiController;
use Common\ORG\PublicFunction;
use Common\ORG\WxFunction;
use Think\Db;

class PcresumeApiController extends PcApiController{
	
	public function _initialize() {

        $getsecret  = $_SERVER['HTTP_APPSECRET'];
        //取head标签内容
        if(!preg_match('/^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/', $getsecret) && ACTION_NAME<>'getUserInfo'){
            $this->ajaxReturn(1, 'appsecret格式错误');
        }
        if($this->appsecret <> $getsecret && ACTION_NAME<>'getUserInfo'){
            $this->ajaxReturn(1, 'appsecret错误');
        }
        parent::_initialize();
    }
    /**
     * 简历数目
     */
    public function countNum(){
        $data = [];
        //求职者投递得简历列表
        $data['jobsnum'] = M('personal_jobs_apply p')->where(['company_uid'=>$this->userinfo['uid'],'is_del'=>0])->count();
        //顾问推荐的简历
        $where['o.uid']= $this->userinfo['uid'];
        $where['o.fa_type']= ['in',[2,3,4]];
        $data['guwentuijiannum'] =M('order o')
            ->field('o.id,o.oid,o.jobs_id,o.fa_type')
            ->join('right join '.C('DB_PREFIX').'jobs as j on j.id = o.jobs_id')
            ->where($where)
            ->count();
        //收藏的简历
        $data['favoritesnum'] = M('company_favorites c')->where(['c.company_uid'=>$this->userinfo['uid']])->count();
        //回收站
        $data['resumedelnum'] = M('company_resume_del c')->distinct(true)->where(['c.company_uid'=>$this->userinfo['uid']])->count();
//        //已读简历
        $wheres['company_uid'] = ['eq',$this->userinfo['uid']];
        $wheres['is_del'] = ['eq',0];
//        $wheres['p.personal_look'] =['eq',2];
//        $yidu_count = M('personal_jobs_apply p')
//            ->join('left join '.C('DB_PREFIX').'resume as s on s.id = p.resume_id')
//            ->where($wheres)
//            ->count();
        //未读简历
        $wheres['p.personal_look'] =['eq',1];
        $weidu_count = M('personal_jobs_apply p')
            ->join('right join '.C('DB_PREFIX').'resume as s on s.id = p.resume_id')
            ->where($wheres)
            ->count();
      //  $data['yidu_count']=$yidu_count;

        $wherea['c.company_uid'] = ['eq',$this->userinfo['uid']];
        $wherea['c.down_type'] = ['eq',2];
        $wherea['c.is_del'] = ['eq',0];
        //下载简历
        $down_count = M('company_down_resume c')
            ->join('left join '.C('DB_PREFIX').'resume as s on s.id = c.resume_id')
            ->where($wherea)
            ->count();
        $data['down_count']=$down_count;
        $data['weidu_count']=$weidu_count;
        $this->ajaxReturn(0, 'ok',$data );
    }
    /**
     * 求职者投递得简历列表
     */
    public function resumeList(){
        $pagesize = I('pagesize',10);//每页条数
        $page = I('page',1);//页数
        $personal_look = I('personaliook',0);//状态
        $where['company_uid'] = ['eq',$this->userinfo['uid']];
        $where['is_del'] = ['eq',0];
        if(!empty($personal_look)){
            $where['p.personal_look'] =['eq',$personal_look];
        }
        //人才简历
        $count = M('personal_jobs_apply p')
                ->join('left join '.C('DB_PREFIX').'resume as s on s.id = p.resume_id')  
                ->where($where)
                ->count();
        $resumelist = M('personal_jobs_apply p')
                    ->field('p.apply_addtime,p.did,s.id,s.uid,s.fullname,s.sex,s.birthdate,s.education_cn,s.major_cn,s.wage_cn,s.current_cn,s.residence,s.refreshtime,p.jobs_name,p.personal_look')
                    ->join('left join '.C('DB_PREFIX').'resume as s on s.id = p.resume_id')  
                    ->where($where)
                    ->page($page,$pagesize)
                    ->select();
        foreach($resumelist as $k=>$v){
            $speciality = M('resume_education')->field('speciality')->where(['pid'=>$v['id']])->order('education desc')->find();
            $resumelist[$k]['major_cn'] =  $speciality['speciality'];
            $resumelist[$k]['residence'] =D('CategoryDistrict')->getCityName($v['residence']);
            $resumelist[$k]['age'] =get_age($v['birthdate']);
            $resumelist[$k]['refreshtime_cn']= daterange(time(),$v['refreshtime']);
            $resumelist[$k]['photosrc']=avatar($v['uid']);
            $resumelist[$k]['apply_addtime']=date('Y-m-d H:i:s',$v['apply_addtime']);
        }
        $data = $this->get_left_useritem();
        $data['count'] = $count;
        $data['resumelist'] = $resumelist;
        $this->ajaxReturn(0, 'ok',$data );
    }

     /**
     * 已下载简历列表
     */
    public function downloaded(){
        $pagesize = I('pagesize',10);//每页条数
        $page = I('page',1);//页数
       
        $where['c.company_uid'] = ['eq',$this->userinfo['uid']];
        $where['c.down_type'] = ['eq',2];
        $where['c.is_del'] = ['eq',0];
        //人才简历
        $count = M('company_down_resume c')
                ->join('left join '.C('DB_PREFIX').'resume as s on s.id = c.resume_id')  
                ->where($where)
                ->count();
           
        $resumelist = M('company_down_resume c')
                    ->field('c.did ,s.id,s.uid,s.fullname,s.sex,s.birthdate,s.education_cn,s.major_cn,s.wage_cn,s.current_cn,s.residence,s.refreshtime')
                    ->join('left join '.C('DB_PREFIX').'resume as s on s.id = c.resume_id')  
                    ->where($where)
                    ->page($page,$pagesize)
                    ->select();
        foreach($resumelist as $k=>$v){
            $speciality = M('resume_education')->field('speciality')->where(['pid'=>$v['id']])->order('education desc')->find();
            $resumelist[$k]['major_cn'] =  $speciality['speciality'];
            $resumelist[$k]['residence'] =D('CategoryDistrict')->getCityName($v['residence']);
            $resumelist[$k]['age'] =get_age($v['birthdate']);
            $resumelist[$k]['refreshtime_cn']= daterange(time(),$v['refreshtime']);
            $resumelist[$k]['photosrc']=avatar($v['uid']);
        }
        $data = $this->get_left_useritem();
        $data['count'] = $count;
        $data['resumelist'] = $resumelist;
        $this->ajaxReturn(0, 'ok',$data );
    }
     /**
     * 顾问推荐的简历
     */

    public  function gw_tui_resume_list()
    {
        $page=I('page',1);
        $pagesize=I('pagesize',30);
        $fa_type = I('fa_type',0);
        $where['o.uid']= $this->userinfo['uid'];

        if($fa_type){
            $where['o.fa_type']= $fa_type;
        }else{
            $where['o.fa_type']= ['in',[2,3,4]];
        }
        $count=M('order o')
                ->field('o.id,o.oid,o.jobs_id,o.fa_type')
                ->join('right join '.C('DB_PREFIX').'jobs as j on j.id = o.jobs_id')
                ->where($where)
                ->count();
        $rorderlist=M('order o')
                ->field('o.id,o.oid,o.rid,o.jobs_id,o.fa_type')
                ->join('right join '.C('DB_PREFIX').'jobs as j on j.id = o.jobs_id')
                ->where($where)
                ->page($page,$pagesize)
                ->select();
             
        $fa_type = [1=>'常规',2=>'顾问找人才',3=>'悬赏找人才',4=>'顾问主动推荐'];
        $data2= [];
        $i = 0;
        foreach($rorderlist as $k=>$v){
            $data2[$i]['id'] = $v['id'];
            $data2[$i]['jobs_id'] = $v['jobs_id'];
            $data2[$i]['oid'] = $v['oid'];
            $data2[$i]['fa_type'] = $fa_type[$v['fa_type']];
            $jobs = M('jobs')->where(['id'=>$v['jobs_id']])->find();
            $data2[$i]['jobs_name'] = $jobs ['jobs_name'];
            $data2[$i]['amount'] = $jobs ['amount'];
            $gu_wen_jie_dan_order = M('gu_wen_jie_dan_order')->where(['fa_bu_order'=>$v['id']])->select();
            $num = 0;
            foreach($gu_wen_jie_dan_order as $vv){
                $num  += M('guwen_tui_jian_rusume')->where(['guwen_uid'=>$vv['gw_uid'],'jobs_id'=>$vv['jobs_id']])->count();
            }
            $data2[$i]['num'] = $num;
            $i++;
        }
        $data = $this->get_left_useritem();
        $data['count'] = $count;
        $data['resumelist'] = $data2;
        $this->ajaxReturn(0, 'ok',$data );
    }
    /*
		收藏的简历
	*/
    public function resume_favorites()
    {

        $page=I('page',1);
        $pagesize=I('pagesize',10);
        $count=M('company_favorites c')
            ->join('left join '.C('DB_PREFIX').'resume as s on s.id = c.resume_id')
            ->where(['c.company_uid'=>$this->userinfo['uid']])
            ->count();
        $resumelist=M('company_favorites c')
                ->field('c.did,s.id,s.uid,s.fullname,s.sex,s.birthdate,s.education_cn,s.major_cn,s.wage_cn,s.current_cn,s.residence,s.refreshtime')
                ->join('left join '.C('DB_PREFIX').'resume as s on s.id = c.resume_id')
                ->where(['c.company_uid'=>$this->userinfo['uid'],'is_del'=>0])
                ->page($page,$pagesize)
                ->select();
        foreach($resumelist as $k=>$v){
            $speciality = M('resume_education')->field('speciality')->where(['pid'=>$v['id']])->order('education desc')->find();
            $resumelist[$k]['major_cn'] =  $speciality['speciality'];
            $resumelist[$k]['residence'] =D('CategoryDistrict')->getCityName($v['residence']);
            $resumelist[$k]['age'] =get_age($v['birthdate']);
            $resumelist[$k]['refreshtime_cn']= daterange(time(),$v['refreshtime']);
            $resumelist[$k]['photosrc']=avatar($v['uid']);
        }
        $data = $this->get_left_useritem();
        $data['count'] = $count;
        $data['resumelist'] = $resumelist;
        $this->ajaxReturn(0, 'ok',$data );
    }


    /**
     * 回收站
     */
    public function get_del_resume(){
        $page=I('page',1);
        $pagesize=I('pagesize',10);
        $count=M('company_resume_del c')
            ->join('left join '.C('DB_PREFIX').'resume as s on s.id = c.resume_id')
            ->distinct(true)
            ->where(['c.company_uid'=>$this->userinfo['uid']])
            ->count();
        $resumelist=M('company_resume_del c')
                ->field('s.uid,s.fullname,s.sex,s.birthdate,s.education_cn,s.major_cn,s.wage_cn,s.current_cn,s.residence,s.refreshtime')
                ->join('left join '.C('DB_PREFIX').'resume as s on s.id = c.resume_id')
                ->distinct(true)
                ->where(['c.company_uid'=>$this->userinfo['uid']])
                ->page($page,$pagesize)
                ->select();
        foreach($resumelist as $k=>$v){
            $speciality = M('resume_education')->field('speciality')->where(['pid'=>$v['id']])->order('education desc')->find();
            $resumelist[$k]['major_cn'] =  $speciality['speciality'];
            $resumelist[$k]['residence'] =D('CategoryDistrict')->getCityName($v['residence']);
            $resumelist[$k]['age'] =get_age($v['birthdate']);
            $resumelist[$k]['refreshtime_cn']= daterange(time(),$v['refreshtime']);
            $resumelist[$k]['photosrc']=avatar($v['uid']);
        }
        $data = $this->get_left_useritem();
        $data['count'] = $count;
        $data['resumelist'] = $resumelist;
        $this->ajaxReturn(0, 'ok',$data );
    }


    /**
     * 标记已读
     */

    public function markRead(){

        $did=I('did');
        if($did>0){
            $request = M('personal_jobs_apply')->where(['did'=>$did])->save(['personal_look'=>2,'personal_look_time'=>time()]);
            if($request){
                $this->ajaxReturn( 0, '成功！' );
            }
        }
    }
    /**
     * 删除
     */
    public function add_del(){
        $resume_id=I('resume_id');
        $did=I('did');
        $data['resume_id'] =$resume_id;
        $data['company_uid'] = $this->userinfo['uid'];
        $request = M('company_resume_del')->add($data);
        $request2 = M('personal_jobs_apply')->where(['did'=>$did])->save(['is_del'=>1]);
        if($request && $request2){
            $this->ajaxReturn( 0, '成功！' );
        }
    }

    public function add_companydel(){
        $resume_id=I('resume_id');
        $did=I('did');
        $data['resume_id'] =$resume_id;
        $data['company_uid'] = $this->userinfo['uid'];
        $request = M('company_resume_del')->add($data);
        $request2 = M('company_down_resume')->where(['did'=>$did])->save(['is_del'=>1]);
        if($request && $request2){
            $this->ajaxReturn( 0, '成功！' );
        }
    }
    /**
     * 取消收藏
     */
    public function cancelCollection(){
        $did=I('did');
        $request = M('company_favorites')->where(['did'=>$did])->save(['is_del'=>1]);
        if($request){
            $this->ajaxReturn( 0, '成功！' );
        }
    }
}
?>